<template>
  <div class="app-container flex-col minH">
    <div class="topline w100p bgwhite ptb20 radius10 pl10 pr20 justify-between">
      <div>
        <!-- <el-input v-model="input2" style="width: 280px" placeholder="搜尋陪玩ID..." :prefix-icon="Search" class="search" />
        <el-select v-model="value" placeholder="選擇項目類型" size="large" style="width: 240px">
          <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
        <el-time-picker v-model="value2" placeholder="開始時間" />
        <span class="plr10">-</span>
        <el-time-picker v-model="value2" placeholder="結束時間" /> -->
        <el-date-picker v-model="start" type="datetime" placeholder="开始时间" value-format="YYYY-MM-DD HH:mm:ss" />
        <span class="plr10 clr9fa">--</span>
        <el-date-picker v-model="end" type="datetime" placeholder="结束时间" value-format="YYYY-MM-DD HH:mm:ss" />
      </div>
      <div class="noshrink">
        <el-button class="btn2" @click="getBroker()">查詢</el-button>
        <el-button class="btn1" @click="reset()">重置</el-button>
      </div>
    </div>
    <div class="bgblueg ptb30 radius10 w100p mt15 plr80 justify-between">
      <div class="align-center clr3c4 flex1">
        <div>
          <div class="ft46">{{ moneyTotal }}</div>
          <div>經紀人佣金總額（元）</div>
        </div>
      </div>

    </div>
    <div class="mt15 radius10 hidden pb15 flex1 bgwhite  flex-col w100p">
      <div class="flex1 w100p ">
        <el-table :data="tableData" style="width: 100%" cell-class-name="tbcell" header-cell-class-name="hdcell">

          <el-table-column prop="user" label="經紀人用戶訊息" width="200">
            <template #default="scope">
              <span @click="showUser(scope.row.user.id)">{{ scope.row.user.phone }}(ID:{{ scope.row.user.id }})</span>

            </template>
          </el-table-column>
          <el-table-column prop="user.name" label="經紀人用戶昵稱" />

          <el-table-column prop="level" label="經紀人等級" />
          <el-table-column prop="num" label="推廣人數">
            <template #default="scope">
              <div class="align-center">
                <span class="mr10">{{ scope.row.num }}</span>
                <!-- <el-icon>
                  <View />
                </el-icon> -->
              </div>

            </template>
          </el-table-column>
          <el-table-column prop="total_income" label="總收入" width="120">
            <template #default="scope">
              <div class="align-center">
                <span class="mr10">{{ scope.row.total_income }}</span>
                <!-- <el-icon>
                  <View />
                </el-icon> -->
              </div>

            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="plr20 mlauto">
        <!-- <div>小計(元): <span class="ft46 clr3c4 ml10">445587</span> </div> -->
      </div>
      <div class="plr20 mlauto mt20">
        <el-pagination v-model:current-page="currentPage1" prev-text="上一頁" next-text="下一頁" :default-page-size="15" :small="small" :disabled="disabled" :background="true" layout="prev, pager, next, jumper" :total="total1" @size-change="handleSizeChange" @current-change="handleCurrentChange1" />
      </div>

    </div>
    <el-dialog v-model="dialogTableVisible" title="本月紅利排行榜">
      <div class="plr20 justify-between ptb20">
        <div>
          <el-time-picker v-model="value2" placeholder="開始時間" />
          <span class="plr10">-</span>
          <el-time-picker v-model="value2" placeholder="結束時間" />
        </div>
        <div>
          <el-button class="btn2">查詢</el-button>
          <el-button class="btn1">重置</el-button>
        </div>

      </div>
      <el-table :data="tableData" cell-class-name="dialogtbcell" header-cell-class-name="dialoghdcell">
        <el-table-column property="name" label="用戶訊息" min-width="200" />
        <el-table-column property="name" label="用戶昵稱" min-width="200" />
        <el-table-column property="address" label="用戶頭像" width="200">
          <template #default>
            <el-avatar shape="square" :size="50" :fit="'cover'" :src="url" />
          </template>

        </el-table-column>
        <el-table-column property="address" label="禮物金額" width="200" />

      </el-table>
      <div class="  plr20 justify-between mt20">
        <div style="flex:1;" class="clr3c4 bold">總共10條</div>
        <div>小計(元): <span class="ft46 clr3c4 ml10">445587</span> </div>
      </div>
    </el-dialog>
  </div>
</template>

<script setup>
import { Search } from '@element-plus/icons-vue'
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router';
import { broker } from '@/api/statement.js'
import { inject } from 'vue';
const showUser = inject('showUser');
onMounted(() => {
  getBroker()
})
const moneyTotal = ref(0)
// 经纪人报表
const getBroker = () => {
  broker({
    start: start.value,
    end: end.value,
    page: currentPage1.value
  }).then((res) => {
    console.log('经纪人报表', res)
    tableData.value = res.list.data
    total1.value = res.list.total
    moneyTotal.value = res.total
    // current_month.value = res.current_month
    // current_month_total.value = res.current_month_total
  })

}
const reset = () => {
  start.value = ''
  end.value = ''
  getBroker()
}

const dialogShow = (type, row) => {
  dialogType.value = type
  dialogTableVisible.value = true
  if (type == 1) {

  }
}
const start = ref('')
const end = ref('')
const dialogType = ref(1)
const dialogTableVisible = ref(false)
const options = [
  {
    value: 'Option1',
    label: 'Option1',
  },
  {
    value: 'Option2',
    label: 'Option2',
  },
  {
    value: 'Option3',
    label: 'Option3',
  },
  {
    value: 'Option4',
    label: 'Option4',
  },
  {
    value: 'Option5',
    label: 'Option5',
  },
]
const tableData = ref([])
const tableRowClassName = () => {
  return 'tbrow'
}
const currentPage1 = ref(1)
const total1 = ref(0)
const handleSizeChange = (val) => {
  console.log(`${val} items per page`)
}
const handleCurrentChange1 = (val) => {
  console.log(`current page: ${val}`)
  getBroker()
}
const router = useRouter()
const toAdd = () => {
  console.log(router)
  router.push({ path: 'addNotice' })
}
const edit = (type) => {
  router.push({ path: 'signEdit' })
}
</script>

<style lang="scss" scoped>
.search {
  overflow: hidden;
  border-radius: 10px !important;
  padding: 5px 0px;
}
</style>
<style></style>
 